package com.interesting.base.core;

import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.widget.TextView;

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.interesting.R;

public class BaseActivity extends SherlockFragmentActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		setTheme(R.style.Theme_Sherlock_Light);
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		ActionBar bar = getSupportActionBar();
		bar.setBackgroundDrawable(getResources().getDrawable(R.drawable.bluebg));
		bar.setLogo(R.drawable.back_ic);
		bar.setHomeButtonEnabled(true);
		bar.setDisplayShowHomeEnabled(true);

		bar.setCustomView(R.layout.text_only_actionbar_custom_view);//右边未空格
		bar.setDisplayShowCustomEnabled(true);

		super.onCreate(savedInstanceState);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		return super.onCreateOptionsMenu(menu);
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			this.finish();
			return true;
		}
		return super.onOptionsItemSelected(item);

	}

	@Override
	public void setTitle(CharSequence title) {

		TextView tv = (TextView) getSupportActionBar().getCustomView().findViewWithTag("actionbar_title");
		tv.setText(title);
		super.setTitle(title);
	}

}
